﻿using System;
using System.Runtime.InteropServices;
namespace EmacsLauncher
{
    class WinApi
    {
        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]
        private static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);

        public void  hideConsoleWindow(String path)
        {
            for(int i = 0; i < 10; i++)
            {
                IntPtr win= FindWindow("ConsoleWindowClass", path);
                if (win != IntPtr.Zero)
                {
                    ShowWindow(win, 0);
                    return;
                }
                System.Threading.Thread.Sleep(300);
            }

        }
    }
}
